package com.yaorange.certificate.controller.wx;

import com.yaorange.certificate.domain.NjtUserPerfect;
import com.yaorange.certificate.domain.NjtUserRegister;
import com.yaorange.certificate.dto.UserRegisterRequest;
import com.yaorange.certificate.service.INjtUserPerfectService;
import com.yaorange.certificate.service.INjtUserRegisterService;
import com.yaorange.certificate.service.NjtCommonService;
import com.yaorange.certificate.vo.UserInfoVo;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.core.domain.entity.SysUser;
import com.yaorange.common.core.domain.model.LoginBody;
import com.yaorange.framework.web.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author coach tam
 * @email 327395128@qq.com
 * @values 坚持灵活 灵活坚持
 * @since 2025/4/30
 */
@RestController
@RequestMapping("/api/user")
public class NjtUserController {
    @Autowired
    private INjtUserRegisterService njtUserRegisterService;
    @Autowired
    private INjtUserPerfectService njtUserPerfectService;
    @Autowired
    private SysLoginService sysLoginService;
    @Autowired
    private NjtCommonService njtCommonService;

    //    http://localhost:8080/api/user/checkMobilePhone?mobilePhone=11111111111
    @GetMapping("/checkMobilePhone")
    public AjaxResult checkMobilePhone(@RequestParam(value = "mobilePhone") String mobilePhone) {
        njtUserRegisterService.checkMobilePhone(mobilePhone);
        return AjaxResult.success();
    }

    //http://localhost:8080/api/user/sendValidateCode?mobilePhone=18180692791
    @GetMapping("/sendValidateCode")
    public AjaxResult sendValidateCode(@RequestParam(value = "mobilePhone") String mobilePhone) {
        njtUserRegisterService.sendValidateCode(mobilePhone);
        return AjaxResult.success();
    }

    //    Request URL: http://localhost:8080/api/user/register
//    Request Method: POST
//    Body : {"mobilePhone":"13999062584","password":"123456","checkCode":"311468"}
    @PostMapping("/register")
    public AjaxResult register(@RequestBody UserRegisterRequest userRegisterRequest) {
        njtUserRegisterService.register(userRegisterRequest);
        return AjaxResult.success();
    }


    //    Request URL:http://localhost:8080/api/user/login
//    Request Method: POST
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody) {
        String token = sysLoginService.wxLogin(loginBody.getUsername(), loginBody.getPassword());
        AjaxResult result = AjaxResult.success();
        result.put("token", token);
        return result;
    }

    @GetMapping("/queryLoginUser")
    public AjaxResult getUserInfo() {
        UserInfoVo userInfoVo = njtCommonService.getLoginUser();
        return AjaxResult.success(userInfoVo);
    }

    @PostMapping("/perfect")
    public AjaxResult perfect(@RequestBody NjtUserPerfect njtUserPerfect) {
        njtUserPerfectService.perfect(njtUserPerfect);
        return AjaxResult.success();
    }
}
